package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.ProductDetailRequest;
import com.mall.shopping.dto.ProductDetailResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ProductController
 * @Description 查看商品详情
 * @Author fan
 * @Date 2021/5/22 19:42
 **/

@RestController
@RequestMapping("/shopping")
public class ProductController {

    @Reference(timeout = 3000,check = false)
    IProductService iProductService;


    @GetMapping("/product/{id}")
    @Anoymous
    public ResponseData getProductDetail(@PathVariable("id") Long id){
        ProductDetailRequest productDetailRequest = new ProductDetailRequest();
        productDetailRequest.setId(id);
        ProductDetailResponse productDetailResponse = iProductService.getProductDetail(productDetailRequest);
        if (productDetailResponse.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){
            ResponseData responseData = new ResponseUtil<>().setData(productDetailResponse.getProductDetailDto());
            return responseData;
        }
        return new ResponseUtil<>().setErrorMsg(productDetailResponse.getMsg());
    }
}
